﻿using System;
using System.Collections.Generic;
using System.Timers;
using com.youzu.warh.protocol;
using FlowCanvas;
using LogSystem;
using UnityEditor;
using UnityEngine;
using Yoozoo.Gameplay.City;
using Yoozoo.Gameplay.Liberty.AI;
using Yoozoo.Gta.Common;
using Yoozoo.Managers.ResourceManagerV2.Runtime;
using Yoozoo.Mars.Got;

namespace Yoozoo.Gameplay.Liberty.StreetEvent
{
    public class StreetEventShootBottle : StreetEventBase
    {
        public string totalCounterName = "CounterTotal";
        public string playerCounterName = "CounterPlayer";
        
        public override void OnEnter()
        {
            base.OnEnter();
            
            HittableBottle.OnKill += OnShootBottle;
        }

        public override void OnExit()
        {
            base.OnExit();
            
            HittableBottle.OnKill -= OnShootBottle;
        }
        
        public void OnShootBottle(int uniqueId)
        {
            // 个人计数器
            if (uniqueId != LibertyAIUtils.PLAYER_AI_ID)
            {
                if (StreetEventManager.GetInstance().monsterId2InfoMap.TryGetValue(uniqueId,out var d))
                {
                    if (!string.IsNullOrEmpty(d.counterName))
                    {
                        StreetTaskCountUtils.AddValue(d.counterName, 1);  // 怪物被杀死计数
                    }
                }
            }
            else
            {
                StreetTaskCountUtils.AddValue(playerCounterName, 1);  // 怪物被杀死计数
            }

            // 总计数器
            StreetTaskCountUtils.AddValue(totalCounterName, 1);  // 怪物被杀死计数
            
            // 刷新排行榜
            ResidentHandler.Inst.GetFunction("CityLuaFunction.refreshStreetEventRank").Action();
        }
        
    }
}